///////////////////////////////////////////////////////////////////////////////
// Name:        linclass.cpp
// Purpose:     linclass function
// Copyright:   (c) 2006, Ivan Laptev, TT Solutions
// License:     GPL, Please contact us for commercial license.
//              http://www.tt-solutions.com/
///////////////////////////////////////////////////////////////////////////////
#include "objectdet/linclass.h"

#include <sstream>

using namespace std;

/**
 * Evaluate the feature value.
 * We are checking if that feature vector points to a needed half-space. For that we will
 * compute its scalar production with model.W vector (it fixes the half-space frontier)
 * and add a constant (this moves around that frontier) to the result, then compare it to zero.
 *
 * return ((feature * model.W) + model.b) < 0;
 * feature and model.W are vectors of the same size
 * model.b is a scalar
 */
bool linclass(std::vector<double> const & feature, StageRule const & stagerule)
{
    // % binary case
	size_t sws = stagerule.W.size();
	size_t fs = feature.size();
    assert( stagerule.W.size() == feature.size() );

    typedef std::vector<double>::const_iterator iter_t;

    iter_t Wit = stagerule.W.begin();
    iter_t Fit = feature.begin();
    iter_t Fend = feature.end();

    double total = stagerule.b;
    for (; Fit != Fend; ++Fit, ++Wit)
    {
        total += (*Fit)*(*Wit);
    }
    // TODO: check if it has to be '<' or '>' sign
    return total > 0.;
//    else
//      % multi-class case 
//      dfce = model.W'*X + model.b(:)*ones(1,num_data);
//      [dummy,y] = max( dfce );
//    end
}
